package com.itheima03.day11Test;

import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Scanner;

/**
 * @author 刘全
 * @date 2021/7/31
 */
public class Test4 {
    public static void main(String[] args) throws IOException {
        //4. 键盘录入一个字符串，输入身份证号码，将其中的偶数写到当前模块的code.txt文件中
        Scanner sc = new Scanner(System.in);
        String s;
        while (true) {
            System.out.println("请输入身份证号码:");
            s = sc.nextLine();
            if (s.length() == 18) {
                break;
            } else {
                System.out.println("输入有误!");
            }
        }
        FileOutputStream fos = new FileOutputStream("myideaTest\\code.txt");
        for (int i = 0; i < s.length(); i++) {
            int c = s.charAt(i);
            if (c % 2 == 0 && (c >= '0' && c <= '9')) {
                fos.write(c);
            }
        }
        fos.close();
    }
}
